package servlet;

import java.io.ByteArrayOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

public class MyResponse {

	private PrintWriter printWriter;
	private ByteArrayOutputStream outputBuffer;
	private int status;
	private String contentType;
	private String charSet;
	private String message;
	private MyRequest request;
	private List<MyCookie> cookies;

	public MyRequest getRequest() {
		return request;
	}

	public void setRequest(MyRequest request) {
		this.request = request;
	}

	public MyResponse(ByteArrayOutputStream outputBuffer) {
		this.outputBuffer = outputBuffer;
		try {
			OutputStreamWriter o= new OutputStreamWriter(outputBuffer,"utf-8");
			printWriter = new PrintWriter(o);
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		cookies = new ArrayList<MyCookie>();
	}

	public PrintWriter getWriter() {
		return printWriter;
	}

	public void addCookie(String name, String value) {
		MyCookie cookie = new MyCookie(name,value);
		addCookie(cookie);
	}
	
	public void addCookie(MyCookie cookie) {
		cookies.add(cookie);
	}

	public ByteArrayOutputStream getOutputBuffer() {
		return outputBuffer;
	}

	public void setOutputBuffer(ByteArrayOutputStream outputBuffer) {
		this.outputBuffer = outputBuffer;
	}

	public void setStatus(int status) {
		this.status = status;

	}

	public int getStatus() {
		return status;
	}

	public String getContentType() {
		// TODO Auto-generated method stub
		return contentType;
	}

	public void setContentType(String contentType) {
		this.contentType = contentType;
	}

	public String getCharSet() {
		return charSet;
	}

	public void setCharSet(String charSet) {
		this.charSet = charSet;
	}

	public void setMessage(String message) {
		this.message = message;

	}

	public String getMessage() {
		return message;
	}

	public List<MyCookie> getCookies() {
		return cookies;
	}

}
